package com.jianqiao.delivery.scheduled;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * author: cyx
 * create: 2024/8/29 16:25
 **/
@Component
public class ScheduledTasks {

//    @Value("{chromedriver}")
//    private String driverPath = "D:\\Edge下载\\新建文件夹\\新建文件夹\\chromedriver.exe";
    private String driverPath = "C:\\project\\chromedriver.exe";

//    @Scheduled(fixedRate = 900000)
    @Scheduled(cron = "0 0/10 * * * ?")
    public void reportCurrentTime() {
        System.out.println("现在时间: " + System.currentTimeMillis() / 1000);
        openZYUrl();
    }

    public void openZYUrl(){
        System.setProperty("webdriver.chrome.driver", driverPath);
        // 关闭无头模式
        System.setProperty("java.awt.headless", "false");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        ChromeDriver driver = new ChromeDriver(options);

        driver.get("http://www.zonyaa.com/index.php/Wap");

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        driver.quit();
    }
}
